package com.pkk.penguin.frame.know.java.driven.factorybean;

import java.util.Arrays;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

/**
 * @description: bean工厂主测试类
 * @author: peikunkun
 * @create: 2020-08-03 11:35
 **/
@Slf4j
@Component
@ComponentScan(basePackages = "com.pkk.penguin.frame.know.java.driven.factorybean")
public class FactoryBeanMainTests {

  @Test
  public void Administrator_11_20200803113543_factoryBean() {
    System.out.println("欢迎使用单元测试方法【Administrator_11()_20200803113543】");
    System.out.println("此方法测试描述：【FactoryBean工厂bean去生产bean的过程】");
    final AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(
        FactoryBeanMainTests.class);
    final String[] beanDefinitionNames = annotationConfigApplicationContext.getBeanDefinitionNames();
    log.info("______________________________________________________");
    Arrays.stream(beanDefinitionNames).forEach(s -> log.info(s));
    log.info("______________________________________________________");

    final Object personFactoryBean = annotationConfigApplicationContext.getBean("personFactoryBean");
    final Object personFactoryBean1 = annotationConfigApplicationContext.getBean("personFactoryBean");
    log.info("personFactoryBean->" + personFactoryBean);
    log.info("personFactoryBean==personFactoryBean1? " + (personFactoryBean1 == personFactoryBean));
    final Object $personFactoryBean = annotationConfigApplicationContext
        .getBean(BeanFactory.FACTORY_BEAN_PREFIX + "personFactoryBean");
    log.info("$personFactoryBean->" + $personFactoryBean);

  }

}
